package connectfour;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class Board implements Serializable{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	Key key;
	
	@Persistent
	//int grid[][]; // 0 = empty, 1 = host, 2 = opponent
	int grid[];
	
	@Persistent
	int numPieces[]; // stores the number of pieces currently in a row
			
	public Board(){
		grid = new int[64];
		for(int i = 0; i < 64; i++){
			grid[i] = 0;
		}
		
		numPieces = new int[8];
		for(int i = 0; i < 8; i++){
			numPieces[i] = 0;
		}
	}
	public Key getKey(){ return key; }
	public int[] getGrid(){ return grid; }
	public int getValue(int c, int r) {	return grid[c + 8*r]; }
	public int[] getNumPieces(){ return numPieces; }

	public void setGrid(int[] g){ grid = g; }
	public void setGrid(int c, int v){ 
		int r = numPieces[c];
		grid[c + 8*r] = v; 
		numPieces[c]++;
	}
	public void setNumPieces(int[] n){ numPieces = n; }
	public void incNumPieces(int c) { numPieces[c]++; }
}
